package drds.server.net;

import java.io.IOException;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class Reactors {
	private final Reactor[] reactors;
	private volatile int next;

	public Reactors(String name, int poolSize) throws IOException {
		reactors = new Reactor[poolSize];
		for (int i = 0; i < poolSize; i++) {
			Reactor reactor = new Reactor(name + "-" + i);
			reactors[i] = reactor;
			reactor.startup();
		}
	}

	public Reactor getReactor() {

		int i = ++next;
		if (i >= reactors.length) {
			i = next = 0;
		}
		return reactors[i];
	}
}
